package com.example.view;

import javax.swing.*;

public class ShowJProgressBar

{
    private volatile static ShowJProgressBar instance;
    static JProgressBar progressBar;

    static JDialog dialog;

    private ShowJProgressBar(){
        dialog =new JDialog();
        progressBar = new JProgressBar();
        progressBar.setVisible(false);
        dialog.setVisible(false);
    }
    public static ShowJProgressBar getInstance(){
        if(instance == null){
            synchronized (ShowJProgressBar.class){
                if(instance == null){
                    instance = new ShowJProgressBar();
                }
            }
        }
        return instance;
    }
    public void setValue(int value){
        if(value >=0 && value <= 100){
            dialog.setTitle("进度:"+value+"%");
            progressBar.setValue(value);
            dialog.repaint();
            progressBar.repaint();
        }
    }
    public void show(){
        dialog.setTitle("进度条:");
        dialog.setLayout(null);
        dialog.add(progressBar);         //将进度条加入到对话框中
        dialog.setBounds(0,0,150,55);
        progressBar.setBounds(0,0,150,45);
//        d.setSize(500,100);
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

        dialog.setLocationRelativeTo(null);
        dialog.setResizable(false);
        progressBar.setVisible(true);
        dialog.setVisible(true);
    }
    public void close(){
        dialog.dispose();
    }



}
